package cn.gz.demo.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.gz.demo.R;
import cn.gz.demo.dto.User;

/**
 * Created by Liuyz on 2017/11/13.
 */
public class GreendaoUserAdapter extends RecyclerView.Adapter<GreendaoUserAdapter.MyViewHolder> {
    private Activity context;
    private List<User> list;

    public GreendaoUserAdapter(Activity activity, List<User> response) {
        this.context = activity;
        this.list = response;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.greendao_user_list_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final User bean = list.get(position);
        holder.item_name.setText(bean.getName() + "");
        holder.item_age.setText(bean.getAge() + "");
        holder.item_sex.setText(bean.getSex() + "");

    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView item_name;
        private TextView item_age;
        private TextView item_sex;

        public MyViewHolder(View view) {
            super(view);

            item_name = (TextView) view.findViewById(R.id.name);
            item_age = (TextView) view.findViewById(R.id.age);
            item_sex = (TextView) view.findViewById(R.id.sex);
        }
    }
}
